package com.fearless.dao.impl;

import java.sql.SQLException;
import java.util.ArrayList;

import com.fearless.entity.NewsTypeEntity;
import com.fearless.entity.ProductTypeEntity;
import com.fearless.util.DBManager;
import com.fearless.util.QueryResult;

public class NewsTypeDaoImpl {
	public ArrayList<NewsTypeEntity> newsType(){
		ArrayList<NewsTypeEntity> alist= new ArrayList<NewsTypeEntity>();
		String sqlString="select id,create_time,name from news_type";
	    QueryResult rSet=DBManager.executeQuery(sqlString);
	      if (rSet!=null) {
	        try {
	          while (rSet.rs.next()) {
	        	  alist.add(new NewsTypeEntity(rSet.rs.getInt("id"),
	            		rSet.rs.getString("create_time"),
	            		rSet.rs.getString("name")));
	          }
	        } catch (SQLException e) {
	          e.printStackTrace();
	        }
	      }
	      rSet.close();
	    return alist;
	}
	
	public int newsTypeAdd(NewsTypeEntity nEntity) {
 		String sqlString="insert into news_type(name,create_time) values('"+nEntity.getName()+"','"+nEntity.getCreateTime()+"')";
 		 int result= DBManager.executeUpdate(sqlString);
 		return result;
 	}
	
	 public int newsTypeUpdate(NewsTypeEntity nEntity) {
	 		String sqlString="update news_type set name='"+nEntity.getName()+"',create_time='"+nEntity.getCreateTime()+"' where id = '"+nEntity.getId()+"'";
	 		 int result= DBManager.executeUpdate(sqlString);
	 		return result;
	 	}
	 
	 public int newsTypeDelete(int id) {
			// TODO Auto-generated method stub
			String sqlString = "delete from news_type where id = '"+id+"'";
			int result = DBManager.executeUpdate(sqlString);
			return result;
		}
}
